package com.stupidzhe.vbreview.config;

import com.stupidzhe.vbreview.domain.Student;
import com.stupidzhe.vbreview.domain.Teacher;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import redis.clients.jedis.JedisPoolConfig;

/**
 * Created by Mr.W on 2017/5/25.
 * redis设置
 */
@Configuration
public class RedisConfig {

    @Bean
    RedisConnectionFactory jedisConnectionFactory() {
        RedisStandaloneConfiguration configuration = new RedisStandaloneConfiguration();
        configuration.setDatabase(1);
        configuration.setPort(6379);
        configuration.setHostName("127.0.0.1");
        return new JedisConnectionFactory(configuration);
    }

    @Bean
    public RedisTemplate<String, Teacher> redisAdmRecordTemplate() {
        RedisTemplate<String, Teacher> template = new RedisTemplate<>();
        template.setConnectionFactory(jedisConnectionFactory());
        template.setKeySerializer(new StringRedisSerializer());
        template.setEnableTransactionSupport(false);
        return template;
    }

    @Bean
    public RedisTemplate<String, Student> redisStudentTemplate() {
        RedisTemplate<String, Student> template = new RedisTemplate<>();
        template.setConnectionFactory(jedisConnectionFactory());
        template.setKeySerializer(new StringRedisSerializer());
        template.setEnableTransactionSupport(false);
        return template;
    }

    @Bean
    public RedisTemplate<String, String> redisCaptchaTemplate() {
        RedisTemplate<String, String> template = new RedisTemplate<>();
        template.setConnectionFactory(jedisConnectionFactory());
        template.setKeySerializer(new StringRedisSerializer());
        template.setEnableTransactionSupport(false);
        
        return template;
    }

}
